package logic

import (
	"context"
	"gozerogateway/rpc/model/svcmodel"

	"encoding/json"
	"gozerogateway/rpc/svc/internal/svc"
	"gozerogateway/rpc/svc/svcclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type ServiceDeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewServiceDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceDeleteLogic {
	return &ServiceDeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ServiceDeleteLogic) ServiceDelete(in *svcclient.ServiceDeleteReq) (*svcclient.ServiceDeleteResp, error) {
	// todo: add your logic here and delete this line

	//_ = l.svcCtx.UserModel.Update(l.ctx, &sysmodel.SysUser{
	//	Id:             in.Id,
	//	Status:         in.Status,
	//	LastUpdateBy:   in.LastUpdateBy,
	//	LastUpdateTime: time.Now(),
	//})
	err := l.svcCtx.SvcModel.Update(l.ctx, &svcmodel.GatewayServiceInfo{
		IsDelete: 0,
		Id:       in.ID,
	})
	if err != nil {
		reqStr, _ := json.Marshal(in)
		logx.WithContext(l.ctx).Errorf("delete service error,id error,param:%s", reqStr)
		return nil, err
	}
	return &svcclient.ServiceDeleteResp{}, nil
}
